package JPLXtandemGA;

import java.util.List;

import ngenes2.fitness.Fitness;

public class XTfitness implements Fitness<IParameter> {

	private boolean append;
	private final String xmlFileName;
	private final String valuesFileName;
	private final java.util.Properties jProp;

	public XTfitness(java.util.Properties jProp) {
		this.jProp = jProp;
		xmlFileName = jProp.getProperty("XML_FILE_NAME");
		valuesFileName =jProp.getProperty("TXT_PARAM_FILE_NAME");
		append= Boolean.valueOf(jProp.getProperty("APPEND_FILE"));
	}

	@Override
	public double compute(List<IParameter> params) {
		try {
		    XTandemOps.writeXMLFile(params, xmlFileName, valuesFileName, append);
		    
		    if(!append)
		    	append = true;
		    
			return XTandemOps.evaluate(xmlFileName, jProp);
		} catch( Exception e ) {
			throw new RuntimeException(e);
		}
	}

}
